package com.laputa.dao.hibernate;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.laputa.dao.GroundDao;
import com.laputa.dao.model.Ground;

public class GroundDaoHibernate extends HibernateDaoSupport implements GroundDao {

	public void delete(Long id) {
		this.getHibernateTemplate().delete(getGround(id));
	}

	public List getAll() {
		return this.getHibernateTemplate().find("from Ground");
	}

	public Ground getGround(Long id) {
		return (Ground)this.getHibernateTemplate().get(Ground.class, id);
	}

	public List getGroundsByOwner(Long ownerId) {
		List groundList = this.getHibernateTemplate().find("from Ground g where g.owner = " + ownerId);
		return groundList;
	}

	public List getGroundsByUser(Long userId) {
		List groundList = this.getHibernateTemplate().find("from Ground g where g.holder = " + userId);
		return groundList;
	}
	
	public List getGroundsRentByUser(Long userId){
		List groundList = this.getHibernateTemplate().find("from Ground g where g.holder = " + userId + "and g.owner != " + userId);
		return groundList;
	}

	public void save(Ground g) {
		this.getHibernateTemplate().saveOrUpdate(g);
	}

}
